/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.lujotar.ejb;

import com.lujotar.entities.Premio;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author RamiroHenao
 */
@Stateless
public class PremioFacade extends AbstractFacade<Premio> {
    @PersistenceContext(unitName = "LUJOTAR-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public PremioFacade() {
        super(Premio.class);
    }
    
    public List<Premio> consultarPremioId(String id){
        Query query;
        query = em.createNamedQuery("Premio.findById");
        if(id != null && !id.equals("")){
            query.setParameter("id",Integer.valueOf(id));
        }else{
            query.setParameter("id",Integer.valueOf(0));
        }
        return query.getResultList();
    }
    
    public List<Premio> consultarPremios(){
        Query query;
        query = em.createNamedQuery("Premio.findAll");
        return query.getResultList();
    }
    
    public List<Premio> consultarPremiosVigentes(){
        Query query;
        query = em.createNamedQuery("Premio.findByEstado");
        query.setParameter("estado", "ACTIVO");
        return query.getResultList();
    }
    
    public void crearPremio(Premio premio){
        em.persist(premio);
    }
    
    public void desactivarPremio(Premio premio){
        em.merge(premio);
    }
    
}
